package com.local.ApacheCommonsTools.BeanUtils.CopyMapBean;

import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;

public class CopyBeanToMap {

	private PersonBean per;
	
	public void setPer(PersonBean per) {
		this.per = per;
	}

	public Map<String,String> beanToMap(PersonBean per) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException{
		Map<String,String> map = BeanUtils.describe(per);
		return map;
	}
	
	public static void main(String[] args) {
		PersonBean per = new PersonBean();
		per.setAge("23");
		per.setSequence(13564L);
		per.setName("FateSaki");
		CopyBeanToMap cop = new CopyBeanToMap();
		Map<String,String> map = null;
		try {
			map = cop.beanToMap(per);
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Iterator<Map.Entry<String, String>> it = map.entrySet().iterator();
		while(it.hasNext()) {
			Map.Entry<String, String> entry = it.next();
			System.out.println(entry.getKey()+":"+entry.getValue());
		}
		System.exit(0);
	}
}
